package com.situ.day7homework;

import java.util.ArrayList;
import java.util.Scanner;

import com.situ.day3.Students;

public class StudentMananger {						//ArrayList
	public static void main(String[] args) {		//foreach遍历
		Scanner scanner = new Scanner(System.in);
		ArrayList<Students> list = new ArrayList<>();	
			while(true){
				System.out.println("请输入学生的id: ");
				int id = scanner.nextInt();
				System.out.println("请输入学生的姓名： ");
				String name = scanner.next();
				System.out.println("请输入学生的年龄： ");
				int age = scanner.nextInt();
				System.out.println("请输入学生的班级： ");
				String className = scanner.next();	
				Students students = new Students(id,name,age,className);
				list.add(students);						//students赋值给数组
				System.out.println("继续输入按1，退出按0");
				int shu = scanner.nextInt();
				if (shu == 0) {
					System.out.println("结束输入");
					break;
				}
			}															
			
			
			System.out.println("学生成绩列表： ");							//打印所有的学生列表
			for (Students student :list) {
				System.out.println(student);
			}
			
			while (true) {											//死循环
				System.out.println("按id查询按1： ");
				System.out.println("按姓名查询按2： ");
				System.out.println("按年龄查询按3： ");
				System.out.println("按班级查询按4： ");
				System.out.println("退出按0： ");
				int type = scanner.nextInt();						//目的是输入0，退出循环
				if (type == 0) {
					System.out.println("退出程序");
					return;											//退出全部循环
				}
				switch (type) {										//输入的要查询的数字
				case 1:
					System.out.println("请输入要查询学生的id： ");
					int id1 = scanner.nextInt();
					boolean falg = false;                      //先假定是假
					for (Students student:list) {
						int idSearch = student.getId();				//遍历数组把id取出来
						if (idSearch == id1) 	{						//把取出的id与输入的id比较
							System.out.println(student);		//比较完相同的话就进入循环，打印学生的数据
							falg = true; 					//真，不进下面的循环
						}
					}
					if (falg == false) {					//为假进入循环
						System.out.println("没有该id的学生： ");
					}
//					System.out.println("id");
					break;
					
					
				case 2:
//					System.out.println("姓名");
					System.out.println("请输入要查询学生的姓名： ");
					String  name1 = scanner.next();
					boolean flag = false;
					for (Students student:list) {
						String name2 = student.getName();
						if (name1.equals(name2)) {
							System.out.println(student);
							flag = true;
						}
					}
					if (flag == false) {
						System.out.println("没有该学生");
					}
					break;
					
				case 3:
					System.out.println("请输入要查询学生的年龄： ");
					int age1 = scanner.nextInt();
					boolean fal = false;
					for (Students student :list) {
						int age2 = student.getAge();
						if (age1 == age2) {
							System.out.println(student);
							fal = true;
						}
					}
					if (fal = false) {
						System.out.println("找不到该年龄的学生： ");
					}
//					System.out.println("年龄");
					break;
					
					
				case 4:
//					System.out.println("班级");
					System.out.println("请输入要查询学生的班级： ");
					String className1 = scanner.next();
					boolean fa = false;
					for (Students student:list) {
						String className2 = student.getClassName();
						if (className1.equals(className2) ) {
							System.out.println(student);
							fa = true;
						}
					}
					if (fa == false) {
						System.out.println("找不到该班级的学生");
					}
					break;

				default:
					System.out.println("错误");
					break;
				}
			}
		}
	

		
		
		
	}
		
	
		